package com.ihr360.payroll.model.dto.attendance.supperclass;

import com.ihr360.payroll.model.base.IBaseAttendanceRule;
import com.ihr360.payroll.model.dto.salary.meta.PayrollConfig;
import com.ihr360.payroll.model.dto.salary.meta.SalaryField;
import com.ihr360.payroll.type.BasementType;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import java.util.ArrayList;
import java.util.List;

/**
 * 通用计算考勤规则
 */
@MappedSuperclass
public class AbstractCalcAttendanceRule extends AbstractAttendanceRule implements IBaseAttendanceRule {
    /**
     * 引用基数,(仅需要保存公式即可，没必要获取关联关系)
     */
    @ManyToMany(fetch = FetchType.LAZY)
    private List<SalaryField> referenceFields = new ArrayList<>();

    /**
     * 工资表,只有确定了工资表，才能确认引用技术需要的字段
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private PayrollConfig payrollConfig;

    @Column(length = 10)
    @Enumerated(value = EnumType.STRING)
    private BasementType basementType;

    public AbstractCalcAttendanceRule() {
    }

    /**
     * 固定基数
     */
    private Double fixedBase;

    /**
     * 基数比例
     */
    @Column(length = 8)
    private Double baseRatio = 100.0;

    /**
     * 计算比例（平日比例）
     */
    @Column(length = 8)
    private Double numOpRatio = 100.0;

    /**
     * 启用多段记薪
     */
    @Column(nullable = false, columnDefinition = "bit(1) default 0")
    private boolean enableSubsectionPaid = false;

    public boolean getEnableSubsectionPaid() {
        return enableSubsectionPaid;
    }

    public void setEnableSubsectionPaid(boolean enableSubsectionPaid) {
        this.enableSubsectionPaid = enableSubsectionPaid;
    }

    @Override
    public Double getFixedBase() {
        return fixedBase;
    }

    @Override
    public Double getBaseRatio() {
        return baseRatio;
    }

    @Override
    public Double getNumOpRatio() {
        return numOpRatio;
    }

    @Override
    public BasementType getBasementType() {
        return basementType;
    }

    @Override
    public List<SalaryField> getReferenceFields() {
        return referenceFields;
    }

    public void setNumOpRatio(Double numOpRatio) {
        this.numOpRatio = numOpRatio;
    }

    public void setBaseRatio(Double baseRatio) {
        this.baseRatio = baseRatio;
    }

    public void setFixedBase(Double fixedBase) {
        this.fixedBase = fixedBase;
    }

    public void setBasementType(BasementType basementType) {
        this.basementType = basementType;
    }

    public void setPayrollConfig(PayrollConfig payrollConfig) {
        this.payrollConfig = payrollConfig;
    }

    public void setReferenceFields(List<SalaryField> referenceFields) {
        this.referenceFields = referenceFields;
    }
}
